
export default class Range{
    constructor(opts,comp){
        if (typeof opts!=='object') opts = {eq: opts,comp};
        if (comp!=null)opts.comp=comp;
        if (opts.eq!=null)opts.max=opts.min=opts.eq;
        if (opts.includeMax==null) opts.includeMax=true;
        if (opts.includeMin==null) opts.includeMin=true;
        Object.assign(this,opts);
        if (this.comp==null) throw new Error("invalid comparator");
    }

    lt(l,r){return this.comp(l,r);}
    gt(l,r){return this.comp(r,l);}
    le(l,r){return !this.comp(r,l);}
    ge(l,r){return !this.comp(l,r);}
    lc(l,r,include){return include?this.le(l,r):this.lt(l,r);}
    gc(l,r,include){return include?this.ge(l,r):this.gt(l,r);}

    ltMin(val){return this.lt(val,this.min);}
    ltMax(val){return this.lt(val,this.max);}
    gtMin(val){return this.gt(val,this.min);}
    gtMax(val){return this.gt(val,this.max);}
    leMin(val){return this.le(val,this.min);}
    leMax(val){return this.le(val,this.max);}
    geMin(val){return this.ge(val,this.min);}
    geMax(val){return this.ge(val,this.max);}
    lcMin(val){return this.lc(val,this.min,this.includeMin);}
    lcMax(val){return this.lc(val,this.max,this.includeMax);}
    gcMin(val){return this.gc(val,this.min,this.includeMin);}
    gcMax(val){return this.gc(val,this.max,this.includeMax);}
    inRange(val){return this.gcMin(val)&&this.lcMax(val);}
}